<?php
require_once '../common.php';
$productID = @$_REQUEST['i'];
$uploaddir = '../images/';
$file_name = date('YmdHis').basename($_FILES['uploadfile']['name']);
$file = $uploaddir.$file_name;
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
    $result = $db->query("INSERT INTO product_image(product_id,product_image_name)VALUES('$productID','$file_name')");
    if($result){
        $html_str = '<table><tr>';
        $query = $db->query("SELECT * FROM product_image WHERE product_id=".$productID);
        while($row = $db->fetch($query)){
            $html_str .= '<td><img src="images/'.$row['product_image_name'].'" width="100" /></td>';
        }
        $html_str .= '</tr></table>';
        echo $html_str.'~success';
    }else{
        echo "error";
    }
} else {
    echo "error";
}  

?>
